﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：MenuMaintainInfo
// 文件功能描述：菜单维护业务逻辑层
//
// 
// 创建标识：2012-05-11 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class MenuMaintainInfo
    {
        /// <summary>
        /// 菜单编号
        /// </summary>
        public int MenuId
        {
            get;
            set;
        }
        /// <summary>
        /// 菜单名称
        /// </summary>
        public string MenuName
        {
            get;
            set;
        }
        /// <summary>
        /// 菜单类型
        /// </summary>
        public int MenuType
        {
            get;
            set;
        }
        /// <summary>
        /// 菜单类型名称
        /// </summary>
        public string MenuTypeName
        {
            get;
            set;
        }
        /// <summary>
        /// 菜单单价
        /// </summary>
        public decimal MenuPrice
        {
            get;
            set;
        }
        /// <summary>
        /// 菜单备注
        /// </summary>
        public string MenuRemarks
        {
            get;
            set;
        }

        private DataAccessMenuMaintain dar;
        private int Menucount;
        public int _Menucount
        {
            get { return Menucount; }
        }
        public MenuMaintainInfo(bool isgetcount)
        {
            dar = new DataAccessMenuMaintain();
            if (isgetcount)
            {
                Menucount = GetMenucount();
            }
        }
        public MenuMaintainInfo()
        { }

        /// <summary>
        /// 获取菜单数量
        /// </summary>
        /// <returns></returns>
        private int GetMenucount()
        {
            return dar.GetMenucount();
        }

        /// <summary>
        /// 获取菜单数量
        /// </summary>
        /// <returns></returns>
        public int GetMenucount(string where)
        {
            return dar.GetMenucount(where);
        }

        /// <summary>
        /// 获取班组信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<MenuMaintainInfo> SelMenuInfo(int pagesize, int startindex, string strquery)
        {
            IList<MenuMaintainInfo> menlist = new List<MenuMaintainInfo>();
            MenuMaintainInfo meninfo;
            DataSet ds = dar.SelMenuInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                meninfo = new MenuMaintainInfo()
                {
                    MenuId = Convert.ToInt32(item["MenuId"]),
                    MenuName = item["MenuName"].ToString(),
                    MenuTypeName = item["MenuType"].ToString(),
                    MenuPrice = Convert.ToDecimal(item["MenuPrice"])
                };
                menlist.Add(meninfo);
            }
            return menlist;
        }

        /// <summary>
        /// 保存菜单(新增界面下)
        /// </summary>
        /// <param name="men"></param>
        /// <returns></returns>
        public int SaveMenuAdd(MenuMaintainInfo men)
        {
            object[] gropara = new object[] { men.MenuName, men.MenuType, men.MenuPrice, men.MenuRemarks };
            return dar.SaveMenuAdd(gropara);
        }

        /// <summary>
        /// 删除增减款类别
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int DeleteMenu(string ID)
        {
            return dar.DeleteMenu(ID);
        }

        /// <summary>
        /// 根据编号获取一条菜单信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MenuMaintainInfo GetMenuInfoOne(string id)
        {
            dar = new DataAccessMenuMaintain();
            DataSet ds = dar.GetMenuInfoOne(id);
            MenuMaintainInfo info = new MenuMaintainInfo();
            info.MenuId = int.Parse(ds.Tables[0].Rows[0]["MenuId"].ToString());
            info.MenuName = ds.Tables[0].Rows[0]["MenuName"].ToString();
            info.MenuType = Convert.ToInt32(ds.Tables[0].Rows[0]["MenuType"].ToString());
            info.MenuPrice = Convert.ToDecimal(ds.Tables[0].Rows[0]["MenuPrice"].ToString());
            info.MenuRemarks = ds.Tables[0].Rows[0]["MenuRemarks"].ToString();
            return info;
        }

        /// <summary>
        /// 保存菜单(修改界面下)
        /// </summary>
        /// <param name="men"></param>
        /// <returns></returns>
        public int SaveMenuEdit(MenuMaintainInfo men)
        {
            object[] gropara = new object[] { men.MenuId, men.MenuName, men.MenuType, men.MenuPrice, men.MenuRemarks };
            return dar.SaveMenuEdit(gropara);
        }
    }
}
